<!DOCTYPE html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加属性值</title>
    <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/layui@2.6.8/dist/css/layui.css">
    <script src="//cdn.jsdelivr.net/npm/layui@2.6.8/dist/layui.js" charset="utf-8"></script>
</head>

<body>
    <div style="margin: 15px;padding: 15px;background-color: #fff;">
        <form class="layui-form">
            <input type="hidden" name="name_id" value="{$name_id}">
            <div class="layui-form-item">
                <label class="layui-form-label">属性名称</label>
                <div class="layui-input-block">
                    <input type="text" value="{$name_title}" readonly class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">属性值</label>
                <div class="layui-input-block">
                    <input type="text" name="title" value="" lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" lay-submit lay-filter="save">保存</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>

    <script>
        layui.use(['form'], function(args){
          var form = layui.form,
            $ = layui.jquery;
          
            form.on('submit(save)', function(obj){
                $.post('/admins/products/save_property_value', obj.field, function(res){
                    if (res.code) return layer.alert(res.msg, {icon: 2});
                    layer.alert(res.msg, {icon: 1});
                    setTimeout(() => parent.window.location.reload(), 1000);
                }, 'json');
            });
        }); 
    </script>
</body>

</html>